/* ------------------------------------------------------------------------*
 *
 * ------------------------------------------------------------------------*/
#include "com_hal.h"
#include "comtask.h"
#include "osObjects.h"   
#include "cominfo.h"
#include "dataproc.h"


void CmdProc(void);
void WifiCmd(void);
void Cifsr(void);
void ComStringHandle(void);


/*****************************************************************************//*!
* @brief   	com task init .
*               
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/

void ComTask(void *argument) {

    ComInit(9600, COM_PAR_EVEN);

    for(;;){
        vTaskDelay(10);

        if (pdFALSE == xSemaphoreTake(xSemCom, 3000)) {
            TimeToAscii(&TimeCur, ComBuff);
            ComBuff[19] = '\r';
            ComBuff[20] = '\n';
            ComBuff[21] = 0;
            ComStringSend(ComBuff);
        } else {
            ComStringHandle();
        }
    }
}

/*****************************************************************************//*!
* @brief   	String Handle .
*               
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/

void ComStringHandle(void) {
    switch (ComBuff[0]) {
            //case 'A': WifiCmd();break;
        case ':': CmdProc();
            break;
        default: break;
    }

    ComRcvSt = COM_RX_IDLE;
    ComRcvCnt = 0;
}

/*****************************************************************************//*!
* @brief   	Data Handle .
*               
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/

void ComDataHandle(void) {

}

/*****************************************************************************//*!
* @brief   Command Proc .
*               
* @param   none
*
* @return  none
*
* @ Pass/ Fail criteria: none
*****************************************************************************/

void CmdProc() {
    uint8_t Cnt;

    if (CMD_START != ComBuff[0])
        return;

    switch (ComBuff[1]) {
        case 'T': Cnt = 0;
            while (ComInfo[COM_INFO_TEST][Cnt]) {
                ComBuff[Cnt] = ComInfo[COM_INFO_TEST][Cnt];
                Cnt++;
            }
            ComBuff[Cnt] = 0;
            ComStringSend(ComBuff);
            break;
        case 'V': Cnt = 0;
            while (ComInfo[COM_INFO_VER][Cnt]) {
                ComBuff[Cnt] = ComInfo[COM_INFO_VER][Cnt];
                Cnt++;
            }
            ComBuff[Cnt] = 0;
            ComStringSend(ComBuff);
            break;
        default: break;
    }
}


